﻿using Newtonsoft.Json;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace HundSunDBQryServer
{
    internal class HundSunDB
    {
        public static string key = "ttuAdhZvrSz4iOK9ZJJMEhLy7Cd6lJGOiWdaRVs1bw4=";
        public static string iv = "EQtubEQcJmCoKDbpcBdh5w==";
        internal static List<RspQryFundJour> GetFundJours(DateTime startTime,DateTime endTime) 
        {
            List < RspQryFundJour > res=new List<RspQryFundJour>();
            // 设置Oracle数据库连接字符串
            string connectionString = "User Id=hs_user;Password=hundsun;Data Source=//10.16.76.70:1521/nuf20bk;";
            // 创建Oracle连接对象
            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                try
                {
                    // 打开数据库连接
                    connection.Open();
                    OracleCommand command = connection.CreateCommand();
                    command.CommandText = $"select t.fund_account,t.init_date,t.curr_date,t.curr_time,t.branch_no,t.business_flag,t.bank_no,t.occur_balance,y.bank_name,u.branch_name,i.business_name,t.remark from (select  t.* from hs_his.his_fundjour t where t.init_date>='{startTime.ToString("yyyyMMdd")}' and t.init_date<='{endTime.ToString("yyyyMMdd")}' and t.bank_no!='0' and (t.business_flag='2041' or t.business_flag='2042' or t.business_flag='2141' or t.business_flag='2142') ) t,HS_ASSET.BANKARG y,hs_user.allbranch u,hs_user.businflag i where t.bank_no=y.bank_no and t.branch_no=u.branch_no and t.business_flag=i.business_flag";
                    var records = SqlHelp.getRecords(command);
                    foreach (var r in records)
                    {
                        try
                        {
                            RspQryFundJour item = new RspQryFundJour()
                            {
                                BankName = r["bank_name".ToUpper()].ToString(),
                                BusinessName = r["business_name".ToUpper()].ToString(),
                                TradingDay = r["init_date".ToUpper()].ToString(),
                                Date = r["curr_date".ToUpper()].ToString(),
                                Time = r["curr_time".ToUpper()].ToString(),
                                Department = r["branch_name".ToUpper()].ToString(),
                                FundAccount = r["fund_account".ToUpper()].ToString(),
                                OccurBalance = r["occur_balance".ToUpper()].ToString(),
                                Remark= r["remark".ToUpper()].ToString(),
                            };
                            res.Add(item);
                        }
                        catch (Exception)
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(r));
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return res;
        }

    }
}
